package com.cardone.platform.configuration.controller;

import java.util.List;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.configuration.dto.DictionaryTypeDto;
import com.cardone.platform.configuration.service.DictionaryTypeService;

/**
 * 字典类型
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/configuration/dictionaryType/")
@Controller
public class DictionaryTypeController {
	/**
	 * 初始化数据绑定
	 *
	 * @param webDataBinder
	 *          数据绑定
	 */
	// @InitBinder
	// @Deprecated
	// public void initBinder(final WebDataBinder webDataBinder) {
	// }

	/**
	 * 字典类型：删除
	 *
	 * @param deleteDictionaryType
	 *          字典类型对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
	public Callable<ReturnDataDto<String>> deleteJson(final DictionaryTypeDto deleteDictionaryType) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(DictionaryTypeService.class).deleteByIds(deleteDictionaryType);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, DictionaryTypeController.log);
				}
			}
		};
	}

	/**
	 * 字典类型：分页查询
	 *
	 * @param findDictionaryType
	 *          字典类型对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
	public void editHtml(final DictionaryTypeDto findDictionaryType, final Model model) {
		final DictionaryTypeDto dictionaryType = ContextHolder.getBean(DictionaryTypeService.class).findById(DictionaryTypeDto.class, findDictionaryType);

		model.addAttribute("dictionaryType", dictionaryType);
	}

	/**
	 * 字典类型：编辑
	 *
	 * @param findDictionaryType
	 *          字典类型对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<DictionaryTypeDto>> findByIdJson(final DictionaryTypeDto findDictionaryType, final Model model) {
		return new Callable<ReturnDataDto<DictionaryTypeDto>>() {
			@Override
			public ReturnDataDto<DictionaryTypeDto> call() throws Exception {
				try {
					final DictionaryTypeDto dictionaryType = ContextHolder.getBean(DictionaryTypeService.class).findById(DictionaryTypeDto.class, findDictionaryType);

					return ReturnDataUtils.newReturnData(dictionaryType);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, DictionaryTypeController.log);
				}
			}
		};
	}

	/**
	 * 字典类型：查询
	 *
	 * @param findListDictionaryType
	 *          字典类型对象
	 * @return 字典类型对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<List<DictionaryTypeDto>>> findListByLikeCodeJson(final DictionaryTypeDto findListDictionaryType) {
		return new Callable<ReturnDataDto<List<DictionaryTypeDto>>>() {
			@Override
			public ReturnDataDto<List<DictionaryTypeDto>> call() throws Exception {
				try {
					final List<DictionaryTypeDto> dictionaryTypeList = ContextHolder.getBean(DictionaryTypeService.class).findListByLikeCode(DictionaryTypeDto.class, findListDictionaryType);

					return ReturnDataUtils.newReturnData(dictionaryTypeList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, DictionaryTypeController.log);
				}
			}
		};
	}

	/**
	 * 字典类型：分页查询
	 *
	 * @param paginationDictionaryType
	 *          字典类型对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<PaginationDto<DictionaryTypeDto>>> paginationByLikeCodeJson(final DictionaryTypeDto paginationDictionaryType) {
		return new Callable<ReturnDataDto<PaginationDto<DictionaryTypeDto>>>() {
			@Override
			public ReturnDataDto<PaginationDto<DictionaryTypeDto>> call() throws Exception {
				try {
					final PaginationDto<DictionaryTypeDto> dictionaryTypePagination = ContextHolder.getBean(DictionaryTypeService.class).paginationByLikeCode(DictionaryTypeDto.class, paginationDictionaryType);

					return ReturnDataUtils.newReturnData(dictionaryTypePagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, DictionaryTypeController.log);
				}
			}
		};
	}

	/**
	 * 字典类型：分页查询
	 *
	 * @param paginationDictionaryType
	 *          字典类型对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
	public void paginationHtml(final DictionaryTypeDto paginationDictionaryType, final Model model) {
		final PaginationDto<DictionaryTypeDto> dictionaryTypePagination = ContextHolder.getBean(DictionaryTypeService.class).paginationByLikeCode(DictionaryTypeDto.class, paginationDictionaryType);

		model.addAttribute("dictionaryTypePagination", dictionaryTypePagination);
	}

	/**
	 * 字典类型：保存
	 *
	 * @param saveDictionaryType
	 *          字典类型对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
	public Callable<ReturnDataDto<String>> saveJson(final DictionaryTypeDto saveDictionaryType) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(DictionaryTypeService.class).saveByIdOrCode(DictionaryTypeDto.class, saveDictionaryType);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, DictionaryTypeController.log);
				}
			}
		};
	}
}
